package org.sunspotworld;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Random;
import java.util.Vector;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Dani
 */
public class RadioStreamReceiveThread extends Thread{

    private Connection connection;
    private Main main;
    private boolean stop = false;

    public RadioStreamReceiveThread(Main main, Connection connection) throws IOException {
        this.main = main;
        this.connection = connection;
      
//        Vector connections = main.getConnections();
//        for(int i = 0; i < connections.size(); ++i) {
//            Connection con = (Connection)connections.elementAt(i);
//            if(con.getAdress() == address) {
//                connection = con;
//                break;
//            }
//        }
//        connection.open(address, port);
    }

    public void stopThread(){
        stop=true;
    }
    
    public void run() {

        //main.recieveMessage(message);

            while(true) {
                String message = "";
                System.out.println("THREAD running");
                
                   // if(connection.dis.available() != 0){

                         message = connection.receiveMessage();
                         main.receiveConnectionMessage(message, connection.getAdress());
                    //}


                    
            }
    }
}
